package com.JinYuan.controller;

import com.JinYuan.pojo.User;
import com.JinYuan.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 金园
 * @create 2022/5/11
 * @Description
 * @className UserController
 * @packageName com.JinYuan.controller
 */
@Controller
//@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;


    @GetMapping("/users")
    public String findByPage(ModelMap map ,
     @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
     @RequestParam(value = "pageSize",required = false,defaultValue = "2")Integer pageSize){


        PageInfo<User> pageInfo = userService.findByPage(pageNum,pageSize);
        map.put("data",pageInfo);
        return "/login.jsp";
    }


    @GetMapping("/{id}")
    public String findById(@PathVariable("id") Integer id, ModelMap modelMap){
        User user = userService.findById(id);
        System.out.println(user);
        modelMap.put("user", user);   

        return "/index.jsp";
    }
}
